package com.demo.designmode.reponseibility;

/**
 * @Author: jxm
 * @Description: 抽象处理者类
 * @Date: 2023-12-11 15:04
 * @Version: 1.0
 */
public abstract class Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    //该领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    //领导上面还有领导（后续者）
    private Handler nextHandler;

    //设置请假天数范围 上不封顶
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    //设置请假天数范围
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //设置上级领导
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    //各级领导处理请假条方法
    protected abstract void handleLeave(LeaveRequest leave);

    //提交请假条
    public final void submit(LeaveRequest leave){
        if(0 == this.numStart){
            return;
        }
        //如果请假天数达到该领导者的处理要求
        if(leave.getNum() >= this.numStart){
            //该领导进行批审
            this.handleLeave(leave);

            //如果还有上级 并且请假天数超过了当前领导的处理范围
            if(this.nextHandler != null && leave.getNum() > this.numEnd){
                //提交给上级领导进行审批
                this.nextHandler.submit(leave);
            }else{
                System.out.println("流程结束");
            }
        }
    }
}
